package com.xiaohai.big_event_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaohai.big_event_system.mapper.CategoryMapper;
import com.xiaohai.big_event_system.projo.Category;
import com.xiaohai.big_event_system.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * <p>
 * 分类 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-01-15
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public IPage<Category> list(Integer currentPage, Integer pageSize, Category category) {
        Page<Category> page = new Page<>(currentPage, pageSize);
        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        Optional.ofNullable(category.getCategoryName())
                .ifPresent(name -> queryWrapper.like(Category::getCategoryName, name));
        Optional.ofNullable(category.getCategoryAlias())
                .ifPresent(alias -> queryWrapper.like(Category::getCategoryAlias, alias));
        Optional.ofNullable(category.getCreateUser())
                .ifPresent(user -> queryWrapper.eq(Category::getCreateUser, user));
        return this.page(page, queryWrapper);
    }
}
